﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using H2.NET.Controls;
using H2.NET.Business;
using H2.NET.Data.Common;

using System.IO;
using H2.NET.Data.Exceller;
using System.Data.OleDb;



namespace H2.NET.Web.Pages
{
    public partial class PBGD: TaskPage
    {
        #region 属性 Public

        private bool IsLoaded
        {
            get
            {
                return ViewState["IsLoaded"] == null ? false : (bool)ViewState["IsLoaded"];
            }
            set { ViewState["IsLoaded"] = value; }

        }

        public string Key
        {
            get
            {
                return ViewState["Key"] == null ? "" : (string)ViewState["Key"];

            }
            set { ViewState["Key"] = value; }
        }

        public List<object> PWP_1
        {
            get
            {
                if (StoreAPI["PWP_1~" + Key] == null)
                {
                    StoreAPI["PWP_1~" + Key] = new List<object>();
                }

                return (List<object>)StoreAPI["PWP_1~" + Key];
            }
            set { StoreAPI["PWP_1~" + Key] = value; }
        }
        //public List<string> PWP_Area
        //{
        //    get
        //    {
        //        if (StoreAPI["PWP_Area~" + Key] == null)
        //        {
        //            StoreAPI["PWP_Area~" + Key] = new List<string>();
        //        }

        //        return (List<string>)StoreAPI["PWP_Area~" + Key];
        //    }
        //    set { StoreAPI["PWP_Area~" + Key] = value; }
        //}
        public List<string> PWP_Unit
        {
            get
            {
                if (StoreAPI["PWP_Unit~" + Key] == null)
                {
                    StoreAPI["PWP_Unit~" + Key] = new List<string>();
                }

                return (List<string>)StoreAPI["PWP_Unit~" + Key];
            }
            set { StoreAPI["PWP_Unit~" + Key] = value; }
        }
        public List<string> PWP_SBU
        {
            get
            {
                if (StoreAPI["PWP_SBU~" + Key] == null)
                {
                    StoreAPI["PWP_SBU~" + Key] = new List<string>();
                }

                return (List<string>)StoreAPI["PWP_SBU~" + Key];
            }
            set { StoreAPI["PWP_SBU~" + Key] = value; }
        }

        public List<string> PWP_Departmeng
        {
            get
            {
                if (StoreAPI["PWP_Departmeng~" + Key] == null)
                {
                    StoreAPI["PWP_Departmeng~" + Key] = new List<string>();
                }

                return (List<string>)StoreAPI["PWP_Departmeng~" + Key];
            }
            set { StoreAPI["PWP_Departmeng~" + Key] = value; }
        }

        public List<string> PWP_Section
        {
            get
            {
                if (StoreAPI["PWP_Section~" + Key] == null)
                {
                    StoreAPI["PWP_Section~" + Key] = new List<string>();
                }

                return (List<string>)StoreAPI["PWP_Section~" + Key];
            }
            set { StoreAPI["PWP_Section~" + Key] = value; }
        }

        private string[] Contract_Type
        {
            get
            {
                if (StoreAPI["Contract_Type~" + Key] == null)
                {

                    IList<t_BPM_CN116_mContractType> dlts = (t_BPM_CN116_mContractType.status == "1").List<t_BPM_CN116_mContractType>();
                    string[] contract_type = new string[dlts.Count + 1];

                    contract_type[0] = "";
                    for (int i = 0; i < dlts.Count; i++)
                    {
                        contract_type[i + 1] = dlts[i].Contract_Type;
                    }

                    StoreAPI["Contract_Type~" + Key] = contract_type;
                }

                return (string[])StoreAPI["Contract_Type~" + Key];
            }
        }

        private string[] Hiring_Reason
        {
            get
            {
                if (StoreAPI["Hiring_Reason~" + Key] == null)
                {

                    IList<t_BPM_CN116_mHiringReason> dlts = (t_BPM_CN116_mHiringReason.status == "1").List<t_BPM_CN116_mHiringReason>();
                    string[] hiring_reason = new string[dlts.Count + 1];

                    hiring_reason[0] = "";
                    for (int i = 0; i < dlts.Count; i++)
                    {
                        hiring_reason[i + 1] = dlts[i].Hiring_Reason;
                    }

                    StoreAPI["Hiring_Reason~" + Key] = hiring_reason;
                }

                return (string[])StoreAPI["Hiring_Reason~" + Key];
            }
        }

        private string[] Legal_Entity
        {
            get
            {
                if (StoreAPI["Legal_Entity~" + Key] == null)
                {

                    IList<t_BPM_CN117_mLegalEntityName> dlts = (t_BPM_CN117_mLegalEntityName.status == "1").List<t_BPM_CN117_mLegalEntityName>();
                    string[] legal_entity = new string[dlts.Count + 1];

                    legal_entity[0] = "";
                    for (int i = 0; i < dlts.Count; i++)
                    {
                        legal_entity[i + 1] = dlts[i].Legal_Entity;
                    }

                    StoreAPI["Legal_Entity~" + Key] = legal_entity;
                }

                return (string[])StoreAPI["Legal_Entity~" + Key];
            }
        }
        #endregion

       
        #region 事件 Page_Load(页面加载)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                INFO.Text = string.Format("<br/>表单正在被同事“{0}”抢占处理，拒绝提交！", RobUser);
                INFO.Visible = IsOverFlow;
                if (!TaskAPI.IsAllowSubmit) Assessment1.Visible = false;
                //InitDropDownList();
                bool flg1 = (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) ? true : false;
                #region 发起步骤
                if (TaskAPI.IsInitiate)
                {
                    // VD.Checked = true;

                }
                #endregion

                #region 审批环节
                else
                {
                        #region 加载数据并显示
                    t_BPM_CN117 ptc = (t_BPM_CN117.process == TaskAPI.Process & t_BPM_CN117.incident == TaskAPI.Incident).ListFirst<t_BPM_CN117>();
                    if (ptc != null)
                    {
                        ApplicationNo.Text = ptc.ApplicationNo;
                        //VD.Checked                          = vendor.VD_Checked == "1";
                        //SA.Checked = vendor.SA_Checked == "1";
                        Actions.SelectedValue = ptc.Actions;
                        Date.Text = ptc.Time.ToString();
                        Applicator.Text = ptc.UserFullName;
                        //Condition_Type.Text = ptc.Condition_Type;
                        //Sorg_DC.Checked = ptc.Sorg_DC == "1";
                        //Distribution_Channel.Text = ptc.Distribution_Channel; 

                        this.UsersChoose1.USR_Inform_Recruiter_C.Checked = false;
                        this.UsersChoose1.USR_5th_Approver_C.Checked = false;
                        this.UsersChoose1.USR_4th_Approver_C.Checked = false;
                        this.UsersChoose1.USR_3rd_Approver_C.Checked = false;
                        this.UsersChoose1.USR_Final_Approver_C.Checked = false;
                        this.UsersChoose1.USR_Approver_C.Checked = false;
                        if (TaskAPI["R_Inform_Recruiter"] != null)
                        {
                            object[] obj1 = (object[])(TaskAPI["R_Inform_Recruiter"]);
                            for (int i = 0; i <= obj1.GetUpperBound(0); i++)
                            {
                                if (!string.IsNullOrEmpty(obj1[i].ToString()))
                                {
                                    string SQL = "select rtrim(NAME) as username, rtrim(FULLNAME) AS fullname from jobs where rtrim(name)='" + obj1[i].ToString() + "'";
                                    TaskDB.Log("", true, "UserChoose - USR_TextChanged:" + SQL);

                                    DBAPI.Storage("bpmDB1");
                                    DataTable dt = DBAPI.Query(SQL);

                                    //根据查询结果进行赋值
                                    if (dt.Rows.Count > 0)
                                    {
                                        this.UsersChoose1.USR_Inform_Recruiter.Text = dt.Rows[0]["FULLNAME"].ToString();
                                        this.UsersChoose1.USR_Inform_Recruiter_C.Checked = true;
                                    }
                                }
                            }
                        }

                        if (TaskAPI["Seventh_Manager"] != null)
                        {
                            object[] obj1 = (object[])(TaskAPI["Seventh_Manager"]);
                            for (int i = 0; i <= obj1.GetUpperBound(0); i++)
                            {
                                if (!string.IsNullOrEmpty(obj1[i].ToString()))
                                {
                                    string SQL = "select rtrim(NAME) as username, rtrim(FULLNAME) AS fullname from jobs where rtrim(name)='" + obj1[i].ToString() + "'";
                                    TaskDB.Log("", true, "UserChoose - USR_TextChanged:" + SQL);

                                    DBAPI.Storage("bpmDB1");
                                    DataTable dt = DBAPI.Query(SQL);

                                    //根据查询结果进行赋值
                                    if (dt.Rows.Count > 0)
                                    {
                                        this.UsersChoose1.USR_7th_Approver.Text = dt.Rows[0]["FULLNAME"].ToString();

                                    }

                                }
                            }
                        }

                        if (TaskAPI["Sixth_Manager"] != null)
                        {
                            object[] obj1 = (object[])(TaskAPI["Sixth_Manager"]);
                            for (int i = 0; i <= obj1.GetUpperBound(0); i++)
                            {
                                if (!string.IsNullOrEmpty(obj1[i].ToString()))
                                {
                                    string SQL = "select rtrim(NAME) as username, rtrim(FULLNAME) AS fullname from jobs where rtrim(name)='" + obj1[i].ToString() + "'";
                                    TaskDB.Log("", true, "UserChoose - USR_TextChanged:" + SQL);

                                    DBAPI.Storage("bpmDB1");
                                    DataTable dt = DBAPI.Query(SQL);

                                    //根据查询结果进行赋值
                                    if (dt.Rows.Count > 0)
                                    {
                                        this.UsersChoose1.USR_6th_Approver.Text = dt.Rows[0]["FULLNAME"].ToString();

                                    }

                                }
                            }
                        }
                        if (TaskAPI["Fifth_Manager"] != null)
                        {
                            object[] obj1 = (object[])(TaskAPI["Fifth_Manager"]);
                            for (int i = 0; i <= obj1.GetUpperBound(0); i++)
                            {
                                if (!string.IsNullOrEmpty(obj1[i].ToString()))
                                {
                                    string SQL = "select rtrim(NAME) as username, rtrim(FULLNAME) AS fullname from jobs where rtrim(name)='" + obj1[i].ToString() + "'";
                                    TaskDB.Log("", true, "UserChoose - USR_TextChanged:" + SQL);

                                    DBAPI.Storage("bpmDB1");
                                    DataTable dt = DBAPI.Query(SQL);

                                    //根据查询结果进行赋值
                                    if (dt.Rows.Count > 0)
                                    {
                                        this.UsersChoose1.USR_5th_Approver.Text = dt.Rows[0]["FULLNAME"].ToString();
                                       
                                    }
 
                                }
                            }
                        }
                        if (TaskAPI["Fouth_Manager"] != null)
                        {
                            object[] obj1 = (object[])(TaskAPI["Fouth_Manager"]);
                            for (int i = 0; i <= obj1.GetUpperBound(0); i++)
                            {
                                if (!string.IsNullOrEmpty(obj1[i].ToString()))
                                {
                                    string SQL = "select rtrim(NAME) as username, rtrim(FULLNAME) AS fullname from jobs where rtrim(name)='" + obj1[i].ToString() + "'";
                                    TaskDB.Log("", true, "UserChoose - USR_TextChanged:" + SQL);

                                    DBAPI.Storage("bpmDB1");
                                    DataTable dt = DBAPI.Query(SQL);

                                    //根据查询结果进行赋值
                                    if (dt.Rows.Count > 0)
                                    {
                                        this.UsersChoose1.USR_4th_Approver.Text = dt.Rows[0]["FULLNAME"].ToString();
                                        this.UsersChoose1.USR_4th_Approver_C.Checked = true;
                                    }
 
                                }
                            }
                        }
                        if (TaskAPI["Third_Manager"] != null)
                        {
                            object[] obj1 = (object[])(TaskAPI["Third_Manager"]);
                            for (int i = 0; i <= obj1.GetUpperBound(0); i++)
                            {
                                if (!string.IsNullOrEmpty(obj1[i].ToString()))
                                {
                                    string SQL = "select rtrim(NAME) as username, rtrim(FULLNAME) AS fullname from jobs where rtrim(name)='" + obj1[i].ToString() + "'";
                                    TaskDB.Log("", true, "UserChoose - USR_TextChanged:" + SQL);

                                    DBAPI.Storage("bpmDB1");
                                    DataTable dt = DBAPI.Query(SQL);

                                    //根据查询结果进行赋值
                                    if (dt.Rows.Count > 0)
                                    {
                                        this.UsersChoose1.USR_3rd_Approver.Text = dt.Rows[0]["FULLNAME"].ToString();
                                        this.UsersChoose1.USR_3rd_Approver_C.Checked = true;
                                    }
                                    
                                }
                            }
                        }
                        if (TaskAPI["Final_Approver"] != null)
                        {
                            object[] obj1 = (object[])(TaskAPI["Final_Approver"]);
                            for (int i = 0; i <= obj1.GetUpperBound(0); i++)
                            {
                                if (!string.IsNullOrEmpty(obj1[i].ToString()))
                                {
                                    string SQL = "select rtrim(NAME) as username, rtrim(FULLNAME) AS fullname from jobs where rtrim(name)='" + obj1[i].ToString() + "'";
                                    TaskDB.Log("", true, "UserChoose - USR_TextChanged:" + SQL);

                                    DBAPI.Storage("bpmDB1");
                                    DataTable dt = DBAPI.Query(SQL);

                                    //根据查询结果进行赋值
                                    if (dt.Rows.Count > 0)
                                    {
                                        this.UsersChoose1.USR_Final_Approver.Text = dt.Rows[0]["FULLNAME"].ToString();
                                        this.UsersChoose1.USR_Final_Approver_C.Checked = true;
                                    }
                                   
                                }
                            }
                        }
                        if (TaskAPI["Approver"] != null)
                        {
                            object[] obj1 = (object[])(TaskAPI["Approver"]);
                            for (int i = 0; i <= obj1.GetUpperBound(0); i++)
                            {
                                if (!string.IsNullOrEmpty(obj1[i].ToString()))
                                {
                                    string SQL = "select rtrim(NAME) as username, rtrim(FULLNAME) AS fullname from jobs where rtrim(name)='" + obj1[i].ToString() + "'";
                                    TaskDB.Log("", true, "UserChoose - USR_TextChanged:" + SQL);

                                    DBAPI.Storage("bpmDB1");
                                    DataTable dt = DBAPI.Query(SQL);

                                    //根据查询结果进行赋值
                                    if (dt.Rows.Count > 0)
                                    {
                                        this.UsersChoose1.USR_Approver.Text = dt.Rows[0]["FULLNAME"].ToString();
                                        this.UsersChoose1.USR_Approver_C.Checked = true;
                                    }
 
                                }
                            }
                        }
                    #endregion

                        #region 审批项初始化
                        switch (TaskAPI.Step)
                        {
                            case "1st Manager":
                            case "2nd Manager":
                            case "3rd Manager":
                            case "4th Manager":
                            case "5th Manager":
                            case "6th Manager":
                            case "7th Manager":
                                Assessment1.Option.Add(new t_AssessmentOption("Approve", "1", true));
                                Assessment1.Option.Add(new t_AssessmentOption("Reject", "3", false));
                                Assessment1.Option.Add(new t_AssessmentOption("More Info.", "2", false));
                                break;
                        }
                        #endregion
                    }
                #endregion

                    #region 设置控件禁启用
                    //bool flg = (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) ? true : false;

                    //SetEnable(flg, gv_Payment_Term);
                    //SetEnable(TaskAPI.Step == "DMO Maintain", SAP_Code);
                    SetVisible(flg1, Plan_Add, Plan_Delete, Import);
                    Assessment1.Enable = TaskAPI.IsAllowSubmit;
                    SetVisible(TaskAPI.IsAllowSubmit, Send, Split);


                    Attachment1.AllowDelete = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                    Attachment1.AllowUpload = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                    Attachment2.AllowDelete = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                    Attachment2.AllowUpload = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                    //InitTabs();
                    #endregion

                    #region 加深颜色
                    string item = null;
                    string value = null;
                    foreach (Control cr in this.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    if (!flg1 || !TaskAPI.IsAllowSubmit)
                    {

                        foreach (Control cr in form.Controls)
                        {
                            if (cr is DropDownList)
                            {
                                DropDownList tb = (DropDownList)cr;
                                if (!tb.Enabled)
                                {
                                    tb.Enabled = true;
                                    item = tb.SelectedItem.Text;
                                    value = tb.SelectedValue.ToString();
                                    tb.Items.Clear();
                                    tb.Items.Add(new ListItem(item, value));
                                }
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                        foreach (Control cr in form.Controls)
                        {
                            if (cr is TextBox)
                            {
                                TextBox tb = (TextBox)cr;
                                if (!tb.Enabled)
                                {
                                    tb.Enabled = true;
                                    tb.ReadOnly = true;
                                    tb.ForeColor = System.Drawing.Color.DimGray;
                                }
                            }
                        }

                    }

                    #endregion

                }
            }
            InitControls();
        }


        protected override void OnLoad(EventArgs e)
        {
            
            base.OnLoad(e);
        }

        public void InitControls()
        {
            bool flg = TaskAPI.IsAllowSubmit && TaskAPI.IsBeginStep;
            gv_Workforce_Plan.DynamicColumn.Add(new BoundColumn2("00", "No", BoundColumnType2.Label, 0, Align.Left, false, "No", InputType.None, null));
            gv_Workforce_Plan.DynamicColumn.Add(new BoundColumn2("01", "Business Area", BoundColumnType2.DropDownList, 130, Align.Left, flg, "Business_Area", InputType.None, new string[5] { "", "Decorative Paints", "Performance Coatings", "Speciality Chemicals", "Other" }));
            //gv_Workforce_Plan.DynamicColumn.Add(new BoundColumn2("01", "Business Area", BoundColumnType2.DropDownList, 60, Align.Left, flg, "Business_Area", InputType.None, PWP_Area));
            gv_Workforce_Plan.DynamicColumn.Add(new BoundColumn2("02", "Business Unit", BoundColumnType2.DropDownList, 140, Align.Left, flg, "Business_Unit", InputType.None, PWP_Unit));
            gv_Workforce_Plan.DynamicColumn.Add(new BoundColumn2("03", "SBU", BoundColumnType2.DropDownList, 100, Align.Left, flg, "SBU", InputType.None, PWP_SBU));
            gv_Workforce_Plan.DynamicColumn.Add(new BoundColumn2("04", "Department", BoundColumnType2.DropDownList, 100, Align.Left, flg, "WP_Department", InputType.None, PWP_Departmeng));
            gv_Workforce_Plan.DynamicColumn.Add(new BoundColumn2("05", "Sub-function", BoundColumnType2.DropDownList, 100, Align.Left, flg, "Section", InputType.None, PWP_Section));
            gv_Workforce_Plan.DynamicColumn.Add(new BoundColumn2("06", "Job Title /Position", BoundColumnType2.TextBox, 130, Align.Left, flg, "Job_Title", InputType.None, null));
            gv_Workforce_Plan.DynamicColumn.Add(new BoundColumn2("07", "Legal Entity", BoundColumnType2.DropDownList, 250, Align.Left, flg, "Legal_Entity", InputType.None, Legal_Entity));
            gv_Workforce_Plan.DynamicColumn.Add(new BoundColumn2("08", "Location", BoundColumnType2.TextBox, 60, Align.Left, flg, "Location", InputType.None, null));
            gv_Workforce_Plan.DynamicColumn.Add(new BoundColumn2("09", "Contract Type", BoundColumnType2.DropDownList, 100, Align.Left, flg, "Contract_Type", InputType.None, Contract_Type));
            gv_Workforce_Plan.DynamicColumn.Add(new BoundColumn2("10", "Reason for Hiring", BoundColumnType2.DropDownList, 100, Align.Left, flg, "Hiring_Reason", InputType.None, Hiring_Reason));
            gv_Workforce_Plan.DynamicColumn.Add(new BoundColumn2("11", "Hiring Manager", BoundColumnType2.TextBox, 80, Align.Left, flg, "Hiring_Manager", InputType.None, null));
            gv_Workforce_Plan.DynamicColumn.Add(new BoundColumn2("12", "Supported HR Recruiter<br/>/HR Business Partner", BoundColumnType2.TextBox, 170, Align.Left, flg, "HR_Recruiter", InputType.None, null));
            gv_Workforce_Plan.DynamicColumn.Add(new BoundColumn2("13", "Job Level", BoundColumnType2.TextBox, 70, Align.Left, flg, "Job_Level", InputType.None, null));
            gv_Workforce_Plan.DynamicColumn.Add(new BoundColumn2("14", "Expected On Board Month", BoundColumnType2.DropDownList, 150, Align.Left, flg, "Expected_Month", InputType.None, new string[13] { "", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }));
            gv_Workforce_Plan.DynamicColumn.Add(new BoundColumn2("15", "Remarks", BoundColumnType2.TextBox, 200, Align.Left, flg, "Remarks", InputType.None, null));
            gv_Workforce_Plan.Width = 1700;
            
            if (!Page.IsPostBack)
            {
                gv_Workforce_Plan.Key = Key;
              

                //BOM_P1.Visible = true;

                #region 发起步骤
                if (TaskAPI.IsInitiate)
                {
                    List<t_BPM_CN117_Details> lpm_s = new List<t_BPM_CN117_Details>();
                    for (int i = 0; i < 5; i++)
                    {
                        lpm_s.Add(new t_BPM_CN117_Details());
                        lpm_s[i].No = i + 1;
                    }
                    gv_Workforce_Plan.DataSource = lpm_s;


                }
                #endregion

                #region 审批环节
                else
                {
                    IList<t_BPM_CN117_Details> lpm_s = (t_BPM_CN117_Details.process == TaskAPI.Process & t_BPM_CN117_Details.incident == TaskAPI.Incident).List<t_BPM_CN117_Details>();
                    if (lpm_s.Count == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            lpm_s.Add(new t_BPM_CN117_Details());
                            lpm_s[i].No = i + 1;
                        }
                    }
                    gv_Workforce_Plan.DataSource = lpm_s;


                  
                }
                #endregion
            }
            //SetVisible(flg, SEFI_1_Add, SEFI_2_Add);
        }
        #endregion

        
        #region 事件 Send
        protected void Send_Click(object sender, EventArgs e)
        {
            try
            {
                #region 数据验证
               // List<string> vald_s = new List<string>();
                List<Regular> regs = new List<Regular>();
                if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) // 如果是退回的情况，不存在验证
                {
                    List<string> vald_s = new List<string>();
                    vald_s.AddRange(DataValidation());
                    vald_s.AddRange(UsersChoose1.DataValidation());

                    switch (TaskAPI.Step)
                    {
                        case "1st Manager":
                        case "2nd Manager":
                        case "3rd Manager":
                        case "4th Manager":
                        case "5th Manager":
                        case "CA Check":

                            if (Assessment1.Assessment.Opinion == "2")
                            {
                                regs.Add(new Regular(RegularExp.NotEmpty, Assessment1.Assessment.Remark, "Opinion; 请在Remark中写入退回理由"));
                            }
                            else if (Assessment1.Assessment.Opinion == "3")
                            {
                                regs.Add(new Regular(RegularExp.NotEmpty, Assessment1.Assessment.Remark, "Opinion; 请在Remark中写入 拒绝理由"));
                            }
                            break;

                    }

                    if (vald_s.Count > 0)
                    {
                        Anthem.Manager.AddScriptForClientSideEval(string.Format("ShowMessage(\"{0}\", {1});", CombineMessage(vald_s), vald_s.Count));
                        return;
                    }
                  
                }
                #endregion

                #region 引擎传值
                if (TaskAPI.IsBeginStep)
                {
                    if (TaskAPI.IsInitiate)
                    {
                        TaskAPI.UserName = UserAPI.UserName;
                        ApplicationNo.Text = Util.GenerateSequence(((object[])TaskAPI["PrefixNo"])[0].ToString() + "-" + System.DateTime.Now.ToString("yyMM"), "", 4);
                        TaskAPI["ApplicationNo"] = ApplicationNo.Text;
                        TaskAPI["ApplicatorName"] = UserAPI.UserFullName;
                        TaskAPI["Applicator"] = UserAPI.UserName;
                        TaskAPI["ApplicatorEmail"] = UserAPI.Mail;
                        TaskAPI["Department"] = UserAPI.Department;
                        TaskAPI["Remark_by_Initiator"] = Assessment1.Assessment.Remark;
                        TaskAPI["Time"] = System.DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                    }
                    TaskAPI.Summary = (Actions.SelectedItem.Text.Split(',').Length >= 2 ? Actions.SelectedItem.Text.Split(',')[1].Trim() : Actions.Text) + " / " + ApplicationNo.Text;
 
                    TaskAPI["Actions"] = Actions.SelectedValue;

                    if (TaskAPI.IsBeginStep)
                    {
                        #region 从数据库取得流程步骤处理人
                       
                        #endregion

                    }
                }
                else
                {
                    TaskAPI["ApproveResult"] = Assessment1.Assessment.Opinion;
                    TaskAPI["TaskID"]        = TaskAPI.TaskID;

                    #region 退回到某个步骤的处理人
                    if (TaskAPI["R_" + TaskAPI.Step.Replace(" ", "_").Replace("/", "_")] != null)
                    {
                        object[] obj = (object[])(TaskAPI["R_" + TaskAPI.Step.Replace(" ", "_").Replace("/", "_")]);
                        for (int i = 0; i < obj.Length; i++)
                        {
                            obj[i] = null;
                        }

                        obj[0] = UserAPI.UserName;

                        TaskAPI["R_" + TaskAPI.Step.Replace(" ", "_").Replace("/", "_")] = obj;
                    }
                    #endregion
                }

               

                //#region 退回步骤并返回功能 传值
                //if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                //{
                //    TaskAPI["Step"] = Assessment1.JumpStep;
                //    TaskAPI["PreStep"] = TaskAPI.Step;
                //}
                //else
                //{
                //    string PreStep = ((object[])TaskAPI["PreStep"])[0].ToString();
                //    if (PreStep.Trim() != "")
                //    {
                //        TaskAPI["Step"]    = PreStep;
                //        TaskAPI["PreStep"] = "";
                //    }
                //    else
                //    {
                //        TaskAPI["Step"] = "";
                //        TaskAPI["PreStep"] = "";
                //    }
                //}
                //#endregion

                #endregion

                #region 提交步骤
                bool flg=false;
                Storage.TransactionExecute(o =>
                {
                    #region “Fill in the form”步骤
                    if (TaskAPI.IsBeginStep)
                    {
                        t_BPM_CN117 ptc = new t_BPM_CN117();
                        if ((t_BPM_CN117.process == TaskAPI.Process & t_BPM_CN117.incident == TaskAPI.Incident & t_BPM_CN117.userName == UserAPI.UserName).Count<t_BPM_CN117>() > 0)
                        {
                            ptc = (t_BPM_CN117.process == TaskAPI.Process & t_BPM_CN117.incident == TaskAPI.Incident & t_BPM_CN117.userName == UserAPI.UserName).ListFirst<t_BPM_CN117>();
                        }
                        else
                        {
                            ptc.Process = TaskAPI.Process;
                            ptc.Incident = TaskAPI.Incident;
                            ptc.UserName = UserAPI.UserName;
                            ptc.UserFullName = UserAPI.UserFullName;
                            ptc.ApplicationNo = ApplicationNo.Text;
                            ptc.Time = System.DateTime.Now;
                            ptc.Status = 0;
                            ptc.Department = UserAPI.Department;

                           
                        }

                        ptc.First_Approver = this.UsersChoose1.USR_Approver.Text;
                        ptc.Final_Approver = this.UsersChoose1.USR_Final_Approver.Text;
                        ptc.Third_Approver = this.UsersChoose1.USR_3rd_Approver.Text;
                        ptc.Fourth_Approver = this.UsersChoose1.USR_4th_Approver.Text;
                        ptc.Fifth_Approver = this.UsersChoose1.USR_5th_Approver.Text;
                        ptc.Sixth_Approver = this.UsersChoose1.USR_6th_Approver.Text;
                        ptc.Seventh_Approver = this.UsersChoose1.USR_7th_Approver.Text;
                        ptc.Inform_Recruiter = this.UsersChoose1.USR_Inform_Recruiter.Text;
                        //ptc.VD_Category = VD_Category.SelectedValue;
                       
                        
                        
                        //vendor.VD_Checked        = VD.Checked ? "1" : "0";
                        //vendor.SA_Checked        = SA.Checked ? "1" : "0";
                        //vendor.SA2_Checked       = SA2.Checked ? "1" : "0";

                        //#region VD
                        //if (VD.Checked)
                        //{
                          
                        //}
                        //#endregion

                        //#region SA
                        //if (SA.Checked)
                        //{
                           
                        //}
                        //#endregion

                        
                        (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });

                        Storage.Save(Storage.Context1, ptc);
                    }
                    #endregion

                    Save();

                    //#region “DMO Maintain”步骤
                    //if (TaskAPI.Step == "DMO Maintain")
                    //{
                    //    (ptc_PaymentTermChange.process == TaskAPI.Process & ptc_PaymentTermChange.incident == TaskAPI.Incident).Edit<ptc_PaymentTermChange>(p =>
                    //    {
                    //        p.SAP_Code = SAP_Code.Text;
                    //    }    
                    //    );
                    //}
                    //#endregion

                    Storage.Save(Assessment1.Assessment);    //审批意见

                    //多节点退回
                    if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                    {
                        Assessment1.SetAsReturn(true);
                        TaskAPI.DirectActive(Assessment1.JumpStep);
                    }
                    else
                    {
                        Assessment1.SetAsReturn(false);
                    }
                    Assessment1.SubmitTo();

                    flg = TaskAPI.Send();
                });

                //如果数据库写入成功且流程发起成功的情况，将业务表数据与流程实例号进行关联
                if (TaskAPI.IsInitiate)
                {
                    (t_BPM_CN117.process == TaskAPI.Process & t_BPM_CN117.incident == 0 & t_BPM_CN117.userName == UserAPI.UserName).Edit<t_BPM_CN117>(p => 
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Assessment.process == TaskAPI.Process & t_Assessment.incident == 0 & t_Assessment.userName == UserAPI.UserName).Edit<t_Assessment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username== UserAPI.UserName).Edit<t_Attachment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });


                    (t_BPM_CN117_Details.process == TaskAPI.Process & t_BPM_CN117_Details.incident == 0 & t_BPM_CN117_Details.userName == UserAPI.UserName).Edit<t_BPM_CN117_Details>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    
                }
                #endregion

                Send.Visible = false;
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Success + "',true)");
            }
            catch (Exception ex)
            {
                TaskDB.Log("", false, "调用NVA方法Send_Click出错：" + ex.ToString());
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Failed + "',false)");
            }
        }
        #endregion

       

        #region 方法 InitDropdownList
        private void InitDropDownList()
        {
            if (!IsLoaded)
            {
                
                IsLoaded = true;
            }
        }
        #endregion

        #region 方法 Save(保存数据库)
        public void Save()
        {
            //if (!Status.IsEdited)
            //{
            //    return;
            //}

            foreach (t_BPM_CN117_Details lpm_1 in (List<t_BPM_CN117_Details>)gv_Workforce_Plan.DataSource)
            {
                if (string.IsNullOrEmpty(lpm_1.Job_Title) && string.IsNullOrEmpty(lpm_1.Business_Area) && string.IsNullOrEmpty(lpm_1.Business_Unit) && string.IsNullOrEmpty(lpm_1.SBU) && string.IsNullOrEmpty(lpm_1.WP_Department) && string.IsNullOrEmpty(lpm_1.Section) && string.IsNullOrEmpty(lpm_1.Legal_Entity) && string.IsNullOrEmpty(lpm_1.Location) && string.IsNullOrEmpty(lpm_1.Contract_Type) && string.IsNullOrEmpty(lpm_1.Hiring_Reason) && string.IsNullOrEmpty(lpm_1.Hiring_Manager) && string.IsNullOrEmpty(lpm_1.HR_Recruiter) && string.IsNullOrEmpty(lpm_1.Job_Level))
                {
                    continue;
                }
                if (TaskAPI.IsBeginStep)
                {
                    
                    //lpm_1.Keys = Keys.Items[0].Selected ? "1" : "0";
                    //lpm_1.Keys2 = Keys.Items[1].Selected ? "1" : "0";
                }
                lpm_1.Process = TaskAPI.Process;
                lpm_1.Incident = TaskAPI.Incident;
                lpm_1.UserName = UserAPI.UserName;
                
                lpm_1.Time = System.DateTime.Now;
                lpm_1.Status = 0;
               
                Storage.Save(lpm_1);
            }

        }

        #endregion

        #region 事件 Add(增加行)
        protected void Add_Click(object sender, EventArgs e)
        {
            List<t_BPM_CN117_Details> list_1_s = (List<t_BPM_CN117_Details>)gv_Workforce_Plan.DataSource;
            t_BPM_CN117_Details list_1 = new t_BPM_CN117_Details();
            list_1.No = list_1_s.Count + 1;
            //list_1_s.Insert(gv_List_Price.ChangedRowIndex == -1 || gv_List_Price.ChangedRowIndex >= list_1_s.Count ? list_1_s.Count + 1 : gv_List_Price.ChangedRowIndex+1, list_1);
            list_1_s.Insert(list_1_s.Count, list_1);
            gv_Workforce_Plan.DataSource = list_1_s;
            gv_Workforce_Plan.DataBind();
        }
        #endregion

        #region 事件 Delete(删除行)
        protected void Delete_Click(object sender, EventArgs e)
        {

            List<t_BPM_CN117_Details> base_1_s = (List<t_BPM_CN117_Details>)gv_Workforce_Plan.DataSource;
            IList<t_BPM_CN117_Details> base1 = (t_BPM_CN117_Details.process == TaskAPI.Process & t_BPM_CN117_Details.incident == TaskAPI.Incident).List<t_BPM_CN117_Details>();
            if (base_1_s.Count == 1)
            {

                return;
            }
            base_1_s.RemoveAt(gv_Workforce_Plan.ChangedRowIndex == -1 || gv_Workforce_Plan.ChangedRowIndex >= base_1_s.Count ? base_1_s.Count - 1 : gv_Workforce_Plan.ChangedRowIndex);
            bool flag = false;
            foreach (t_BPM_CN117_Details base_1 in base1)
            {

                foreach (t_BPM_CN117_Details base_2 in base_1_s)
                {
                    if (base_2.ID == base_1.ID)
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    Storage.Delete(base_1);
                }
                flag = false;
            }
            gv_Workforce_Plan.DataSource = base_1_s;
            gv_Workforce_Plan.DataBind();
        }
        #endregion

        #region 方法 DataValidation
        private List<string> DataValidation()
        {
            List<string> vald_s = new List<string>();
            
            List<Regular> regs = new List<Regular>();

            #region Workforce Planning
            foreach (t_BPM_CN117_Details BPM in (List<t_BPM_CN117_Details>)gv_Workforce_Plan.DataSource)
            {
                if (string.IsNullOrEmpty(BPM.Business_Area) && string.IsNullOrEmpty(BPM.Business_Unit) && string.IsNullOrEmpty(BPM.SBU) && string.IsNullOrEmpty(BPM.WP_Department) && string.IsNullOrEmpty(BPM.Section) && string.IsNullOrEmpty(BPM.Job_Title) && string.IsNullOrEmpty(BPM.Legal_Entity) && string.IsNullOrEmpty(BPM.Location) && string.IsNullOrEmpty(BPM.Contract_Type) && string.IsNullOrEmpty(BPM.Hiring_Reason) && string.IsNullOrEmpty(BPM.Hiring_Manager) && string.IsNullOrEmpty(BPM.HR_Recruiter) && string.IsNullOrEmpty(BPM.HR_Recruiter) && string.IsNullOrEmpty(BPM.Job_Level) && string.IsNullOrEmpty(BPM.Expected_Month))
                {
                    continue;
                }

                if (string.IsNullOrEmpty(BPM.Business_Area))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BPM.Business_Area, "&nbsp;&nbsp;行" + BPM.No + ":Business Area 为必填 "));
                }


                if (string.IsNullOrEmpty(BPM.Business_Unit))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BPM.Business_Unit, "&nbsp;&nbsp;行" + BPM.No + ":Business Unit 为必填 "));
                }


                if (string.IsNullOrEmpty(BPM.SBU))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BPM.SBU, "&nbsp;&nbsp;行" + BPM.No + ":SBU 为必填 "));
                }

                if (string.IsNullOrEmpty(BPM.WP_Department))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BPM.WP_Department, "&nbsp;&nbsp;行" + BPM.No + ":Department 为必填 "));
                }

                if (string.IsNullOrEmpty(BPM.Section))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BPM.Section, "&nbsp;&nbsp;行" + BPM.No + ":Section 为必填 "));
                }

                if (string.IsNullOrEmpty(BPM.Job_Title))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BPM.Job_Title, "&nbsp;&nbsp;行" + BPM.No + ":Job Title /Position 为必填 "));
                }

                if (string.IsNullOrEmpty(BPM.Legal_Entity))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BPM.Legal_Entity, "&nbsp;&nbsp;行" + BPM.No + ":Legal Entity 为必填 "));
                }

                if (string.IsNullOrEmpty(BPM.Location))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BPM.Location, "&nbsp;&nbsp;行" + BPM.No + ":Location 为必填 "));
                }

                if (string.IsNullOrEmpty(BPM.Contract_Type))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BPM.Contract_Type, "&nbsp;&nbsp;行" + BPM.No + ":Contract Type 为必填 "));
                }

                if (string.IsNullOrEmpty(BPM.Hiring_Reason))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BPM.Hiring_Reason, "&nbsp;&nbsp;行" + BPM.No + ":Hiring Manager 为必填 "));
                }

                if (string.IsNullOrEmpty(BPM.Hiring_Manager))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BPM.Hiring_Manager, "&nbsp;&nbsp;行" + BPM.No + ":Reason for Hiring 为必填 "));
                }

                if (string.IsNullOrEmpty(BPM.HR_Recruiter))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BPM.HR_Recruiter, "&nbsp;&nbsp;行" + BPM.No + ":Supported HR Recruiter/HR Business Partner 为必填 "));
                }

                if (string.IsNullOrEmpty(BPM.Job_Level))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BPM.Job_Level, "&nbsp;&nbsp;行" + BPM.No + ":Job Level 为必填 "));
                }

                if (string.IsNullOrEmpty(BPM.Expected_Month))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BPM.Expected_Month, "&nbsp;&nbsp;行" + BPM.No + ":Expected On Board Month 为必填 "));
                }
            }


            return Validation(regs);
            if (vald_s.Count > 0)
            {
                vald_s.Insert(0, "<font color='#0000FF'><b>Budget </b></font>");
            }
          
            #endregion

            return vald_s;
        }
        #endregion

        #region 方法 gv_Workforce_Plan 数据取得
        protected void gv_Workforce_Plan_DataBinding(object sender, EventArgs e)
        {
            List<t_BPM_CN117_Details> ccc_s = gv_Workforce_Plan.DataSource as List<t_BPM_CN117_Details>;
            int row = gv_Workforce_Plan.SelectedIndex;
            int selectcolumnIndex = gv_Workforce_Plan.EditIndex;
            if ((TaskAPI.IsBeginStep) && TaskAPI.IsAllowSubmit && selectcolumnIndex == 2)
            {
                int i = 0;
                foreach (t_BPM_CN117_Details ccc in ccc_s)
                {
                    if (i == row)
                    {
                        PWP_Unit.Clear();
                        IList<t_BPM_CN116_mBussiness> ncc = (t_BPM_CN116_mBussiness.bA == ccc.Business_Area).List<t_BPM_CN116_mBussiness>();
                        foreach (t_BPM_CN116_mBussiness rec in ncc)
                        {
                            if (!PWP_Unit.Contains(rec.BU))
                            {
                                PWP_Unit.Add(rec.BU);
                            }
                        }
                        //ViewState["Unit" + (row + 100).ToString()] = PWP_Unit;
                    }
                    i++;
                }
            }
            if ((TaskAPI.IsBeginStep) && TaskAPI.IsAllowSubmit && selectcolumnIndex == 3)
            {
                PWP_SBU.Clear();
                int i = 0;

                foreach (t_BPM_CN117_Details ccc in ccc_s)
                {
                    if (i == row)
                    {
                        IList<t_BPM_CN116_mBussiness> ncc = (t_BPM_CN116_mBussiness.bA == ccc.Business_Area & t_BPM_CN116_mBussiness.bU == ccc.Business_Unit).List<t_BPM_CN116_mBussiness>();
                        if (ncc.Count > 0)
                        {
                            PWP_SBU.Clear();
                        }
                        foreach (t_BPM_CN116_mBussiness rec in ncc)
                        {
                            if (!PWP_SBU.Contains(rec.SBU))
                            {
                                PWP_SBU.Add(rec.SBU);
                            }
                        }

                    }
                    i++;
                }


            }
            if ((TaskAPI.IsBeginStep) && TaskAPI.IsAllowSubmit && selectcolumnIndex == 4)
            {
                PWP_Departmeng.Clear();
                int i = 0;
                foreach (t_BPM_CN117_Details ccc in ccc_s)
                {
                    if (i == row)
                    {

                        IList<t_BPM_CN116_mBussiness> ncc = (t_BPM_CN116_mBussiness.bA == ccc.Business_Area & t_BPM_CN116_mBussiness.bU == ccc.Business_Unit & t_BPM_CN116_mBussiness.sBU == ccc.SBU).List<t_BPM_CN116_mBussiness>();

                        if (ncc.Count > 0)
                        {
                            PWP_Departmeng.Clear();
                        }
                        foreach (t_BPM_CN116_mBussiness rec in ncc)
                        {
                            if (!PWP_Departmeng.Contains(rec.Department))
                            {
                                PWP_Departmeng.Add(rec.Department);
                            }
                        }

                    }
                    i++;
                }
            }
            if ((TaskAPI.IsBeginStep) && TaskAPI.IsAllowSubmit && selectcolumnIndex == 5)
            {
                PWP_Section.Clear();
                int i = 0;

                foreach (t_BPM_CN117_Details ccc in ccc_s)
                {
                    if (i == row)
                    {
                        IList<t_BPM_CN116_mBussiness> ncc = (t_BPM_CN116_mBussiness.bA == ccc.Business_Area & t_BPM_CN116_mBussiness.bU == ccc.Business_Unit & t_BPM_CN116_mBussiness.sBU == ccc.SBU & t_BPM_CN116_mBussiness.department == ccc.WP_Department).List<t_BPM_CN116_mBussiness>();
                        if (ncc.Count > 0)
                        {
                            PWP_Departmeng.Clear();
                        }
                        foreach (t_BPM_CN116_mBussiness rec in ncc)
                        {
                            if (!PWP_Section.Contains(rec.Section))
                            {
                                PWP_Section.Add(rec.Section);
                            }
                        }
                    }
                    i++;
                }
            }
        }
        #endregion

        #region 事件 Import_Click
        protected void Import_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Attachment2.FirstFilePath) || Attachment2.FirstFilePath.ToLower().LastIndexOf(".xls") == -1)
            {
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('模板文件未上传或导入模板文件格式不正确！',false)");
                return;
            }
            try
            {
                //生成连接Excel数据表格的字符串
                string strOdbcCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Attachment2.FirstFilePath + ";Extended properties=\"Excel 8.0;Imex=1;HDR=Yes;\""; 
                //定义OleDbConnection对象实例并连接Excel表格
                OleDbConnection OleDB = new OleDbConnection(strOdbcCon);
                //定义OleDbDataAdapter对象实例并调用Select查询语句提取Excel数据信息
                System.Data.OleDb.OleDbDataAdapter OleDat = new OleDbDataAdapter("select * from [Sheet1$]", OleDB);
                DataTable dt = new DataTable();    //定义DataTable对象实例
                OleDB.Open();
                OleDat.FillSchema(dt, SchemaType.Mapped); 
                OleDat.Fill(dt);                   //调用Fill方法
                OleDB.Close();
                //Anthem.Manager.AddScriptForClientSideEval("JSInfomation('模板第" + dt.Rows.Count + "行数据不正确！',false)");
                //连接数据表格，显示数据
                List<t_BPM_CN117_Details> sb1_s = new List<t_BPM_CN117_Details>();

                PWP_1.Clear();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    t_BPM_CN117_Details sb1 = new t_BPM_CN117_Details();
                    sb1.Business_Area = dt.Rows[i][0].ToString().Trim();
                    sb1.Business_Unit = dt.Rows[i][1].ToString().Trim();
                    sb1.SBU = dt.Rows[i][2].ToString().Trim();
                    sb1.WP_Department = dt.Rows[i][3].ToString().Trim();
                    sb1.Section = dt.Rows[i][4].ToString().Trim();
                    sb1.Job_Title = dt.Rows[i][5].ToString().Trim();
                    sb1.Legal_Entity = dt.Rows[i][6].ToString().Trim();
                    sb1.Location = dt.Rows[i][7].ToString().Trim();
                    sb1.Contract_Type = dt.Rows[i][8].ToString().Trim();
                    sb1.Hiring_Reason = dt.Rows[i][9].ToString().Trim();
                    sb1.Hiring_Manager = dt.Rows[i][10].ToString().Trim();
                    sb1.HR_Recruiter = dt.Rows[i][11].ToString().Trim();
                    sb1.Job_Level = dt.Rows[i][12].ToString().Trim();
                    sb1.Expected_Month = dt.Rows[i][13].ToString().Trim();
                    sb1.Remarks = dt.Rows[i][14].ToString().Trim();
                    IList<t_BPM_CN116_mBussiness> ncc = (t_BPM_CN116_mBussiness.section == sb1.Section & t_BPM_CN116_mBussiness.bA == sb1.Business_Area & t_BPM_CN116_mBussiness.bU == sb1.Business_Unit & t_BPM_CN116_mBussiness.sBU == sb1.SBU & t_BPM_CN116_mBussiness.department == sb1.WP_Department).List<t_BPM_CN116_mBussiness>();

                    if (!string.IsNullOrEmpty(sb1.Business_Area) || !string.IsNullOrEmpty(sb1.Business_Unit) || !string.IsNullOrEmpty(sb1.SBU) || !string.IsNullOrEmpty(sb1.WP_Department) || !string.IsNullOrEmpty(sb1.Section) || !string.IsNullOrEmpty(sb1.Legal_Entity) || !string.IsNullOrEmpty(sb1.Job_Title) || !string.IsNullOrEmpty(sb1.Location) || !string.IsNullOrEmpty(sb1.Contract_Type) || !string.IsNullOrEmpty(sb1.Hiring_Reason) || !string.IsNullOrEmpty(sb1.Hiring_Manager) || !string.IsNullOrEmpty(sb1.HR_Recruiter) || !string.IsNullOrEmpty(sb1.Job_Level) || !string.IsNullOrEmpty(sb1.Expected_Month))
                    {
                        sb1_s.Add(sb1);
                        if (ncc.Count == 0)
                        {                    
                            Anthem.Manager.AddScriptForClientSideEval("JSInfomation('模板第" + (i + 1) + "行数据不正确！',false)");
                            return;
                        }
                    }

                }
                PWP_1.Add(sb1_s);
                gv_Workforce_Plan.DataSource = PWP_1[0];
                 Anthem.Manager.AddScriptForClientSideEval("document.getElementById('logo').click();");
                //Import.Enabled = true;
            }
            catch (Exception ey)
            {
                throw ey;   
            }
            Import.Visible = true;
        }
        #endregion

        #region 辅助类 WorkPlan_T
        public class WorkPlan_T
        {

            public ArrayList _Business_Area = new ArrayList();
            public ArrayList _Business_Unit = new ArrayList();
            public ArrayList _SBU = new ArrayList();
            public ArrayList _WP_Department = new ArrayList();
            public ArrayList _Section = new ArrayList();
            public ArrayList _Job_Title = new ArrayList();
            public ArrayList _Legal_Entity = new ArrayList();
            public ArrayList _Location = new ArrayList();
            public ArrayList _Contract_Type = new ArrayList();
            public ArrayList _Hiring_Reason = new ArrayList();
            public ArrayList _Hiring_Manager = new ArrayList();
            public ArrayList _HR_Recruiter = new ArrayList();
            public ArrayList _Job_Level = new ArrayList();
            public ArrayList _Expected_Month = new ArrayList();
            public ArrayList _Remarks = new ArrayList();


            [FromRange("A2", "A499")]
            [ToRange("A2", "A499")]
            public ArrayList Business_Area
            {
                get { return _Business_Area; }
                set { _Business_Area = value; }
            }

            [FromRange("B2", "B499")]
            [ToRange("B2", "B499")]
            public ArrayList Business_Unit
            {
                get { return _Business_Unit; }
                set { _Business_Unit = value; }
            }

            [FromRange("C2", "C499")]
            [ToRange("C2", "C499")]
            public ArrayList SBU
            {
                get { return _SBU; }
                set { _SBU = value; }
            }

            [FromRange("D2", "D499")]
            [ToRange("D2", "D499")]
            public ArrayList WP_Department
            {
                get { return _WP_Department; }
                set { _WP_Department = value; }
            }

            [FromRange("E2", "E499")]
            [ToRange("E2", "E499")]
            public ArrayList Section
            {
                get { return _Section; }
                set { _Section = value; }
            }

            [FromRange("F2", "F499")]
            [ToRange("F2", "F499")]
            public ArrayList Job_Title
            {
                get { return _Job_Title; }
                set { _Job_Title = value; }
            }

            [FromRange("G2", "G499")]
            [ToRange("G2", "G499")]
            public ArrayList Legal_Entity
            {
                get { return _Legal_Entity; }
                set { _Legal_Entity = value; }
            }

            [FromRange("H2", "H499")]
            [ToRange("H2", "H499")]
            public ArrayList Location
            {
                get { return _Location; }
                set { _Location = value; }
            }

            [FromRange("I2", "I499")]
            [ToRange("I2", "I499")]
            public ArrayList Contract_Type
            {
                get { return _Contract_Type; }
                set { _Contract_Type = value; }
            }

            [FromRange("J2", "J499")]
            [ToRange("J2", "J499")]
            public ArrayList Hiring_Reason
            {
                get { return _Hiring_Reason; }
                set { _Hiring_Reason = value; }
            }

            [FromRange("K2", "K499")]
            [ToRange("K2", "K499")]
            public ArrayList Hiring_Manager
            {
                get { return _Hiring_Manager; }
                set { _Hiring_Manager = value; }
            }

            [FromRange("L2", "L499")]
            [ToRange("L2", "L499")]
            public ArrayList HR_Recruiter
            {
                get { return _HR_Recruiter; }
                set { _HR_Recruiter = value; }
            }

            [FromRange("M2", "M499")]
            [ToRange("M2", "M499")]
            public ArrayList Job_Level
            {
                get { return _Job_Level; }
                set { _Job_Level = value; }
            }

            [FromRange("N2", "N499")]
            [ToRange("N2", "N499")]
            public ArrayList Expected_Month
            {
                get { return _Expected_Month; }
                set { _Expected_Month = value; }
            }

            [FromRange("O2", "O499")]
            [ToRange("O2", "O499")]
            public ArrayList Remarks
            {
                get { return _Remarks; }
                set { _Remarks = value; }
            }
        }
        #endregion

        #region 方法 Others
        protected void VD_Payment_Methods_SelectedIndexChanged(object sender, EventArgs e)
        {
           
        }
        private string getFormCheckList(Anthem .CheckBoxList ck)
        {
            string t = "";
            for (int i = 0; i < ck.Items.Count; i++)
                if (ck.Items[i].Selected)
                    t += "," + ck.Items[i].Value;
                else
                    t += ",";
            return t;
        }
        private Anthem.CheckBoxList setCheckList(string t, Anthem .CheckBoxList ck)
        {
            try
            {
                string[] tt = t.Split(',');

                for (int i = 0; i <= tt.GetUpperBound(0); i++)
                {
                    for (int j = 0; j < ck.Items.Count; j++)
                    {
                        if (ck.Items[j].Value == tt[i].ToString())
                        { ck.Items[j].Selected = true; break; }
                    }
                }
            }
            catch { }
            return ck;
        }
        #endregion
        protected void logo_Click(object sender, ImageClickEventArgs e)
        {

        }

       
    }
}